package trlygjj.tanruiliyigenjinjin.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import trlygjj.tanruiliyigenjinjin.domain.EmployeeNeeds;
import trlygjj.tanruiliyigenjinjin.page.PageResult;
import trlygjj.tanruiliyigenjinjin.query.EmployeeNeedsQueryObject;
import trlygjj.tanruiliyigenjinjin.service.IEmployeeNeedsService;
import trlygjj.tanruiliyigenjinjin.util.JsonResult;

import java.util.List;

/**
 * Created by user on 2018/7/11.
 */
@Controller
@RequestMapping("employeeNeeds")
public class EmployeeNeedsController {

    @Autowired
    private IEmployeeNeedsService employeeNeedsService;

    /**
     * 提供一个默认不输入后缀,直接可以跳转到具有分页的列表页面
     * @return
     */
    @RequestMapping("")
    public String index(){
        return "employeeNeeds/list";
    }

    /**
     * 具有分页和高级查询
     * @return
     */
    @RequestMapping("list")
    @ResponseBody()
    public PageResult list(EmployeeNeedsQueryObject qo){
        PageResult result = employeeNeedsService.query(qo);
        return result;
    }

    /**
     * 查询全部
     * @return
     */
    @RequestMapping("listAll")
    @ResponseBody()
    public List<EmployeeNeeds> listAll(){
        return employeeNeedsService.selectAll();
    }

    /**
     * 删除
     * @param employeeNeedsId 要删除的员工对象id
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long employeeNeedsId){
        JsonResult result = new JsonResult();
        try{
            employeeNeedsService.deleteByPrimaryKey(employeeNeedsId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }

    /**
     *更新
     * @param employeeNeeds 要更新的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(EmployeeNeeds employeeNeeds){
        JsonResult result = new JsonResult();
        try{
            employeeNeedsService.updateByPrimaryKey(employeeNeeds);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }
    /**
     *查询还没审核的用人需求
     * @return 返回Js还没审核的用人需求
     */
    @RequestMapping("selectUnreviewed")
    @ResponseBody
    public  List<EmployeeNeeds> selectUnreviewed(){

        return employeeNeedsService.selectUnreviewed();
    }

    /**
     * 保存
     * @param employeeNeeds 要保存的员工对象
     * @return 返回JsonResult对象判断是否操作成功
     */
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(EmployeeNeeds employeeNeeds){
        JsonResult result = new JsonResult();
        try{
            employeeNeedsService.insert(employeeNeeds);
        }catch (Exception e){
            e.printStackTrace();
            result.mark("操作失败!");
        }
        return result;
    }
    /**
     * 根据计划的id查询用人需求
     * @param recruitmentPlanId 招聘的id
     * @return 返回对应的用人需求
     */
    @RequestMapping("selectEmployeeNeedsByRecruitmentPlanId")
    @ResponseBody
    public List<EmployeeNeeds> selectEmployeeNeedsByRecruitmentPlanId(Long recruitmentPlanId){
        return employeeNeedsService.selectEmployeeNeedsByRecruitmentPlanId(recruitmentPlanId);
    }
}
